﻿<Window x:Class="CalculatorProject.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:View="clr-namespace:CalculatorProject.View"
        xmlns:Graph="clr-namespace:Graphing;assembly=Graphing"
        xmlns:GraphView="clr-namespace:Graphing.View;assembly=Graphing"
        xmlns:GraphViewModel="clr-namespace:Graphing.ViewModel;assembly=Graphing"
        xmlns:ViewModel="clr-namespace:CalculatorProject.ViewModel"
        xmlns:converter="clr-namespace:Graphing;assembly=Graphing"
        Title="Calculator" SizeToContent="WidthAndHeight" WindowStyle="ToolWindow" ResizeMode="NoResize">

    <!-- Resources\Templates -->
    <Window.Resources>
        <!-- Converter to help determin which Radio Button is currently Selected. -->
        <Graph:EnumBoolConverter x:Key="EnumConverter" />
        
        <!-- Graph Main Window View Model variable. -->
        <GraphViewModel:PointsViewModel x:Key="GraphVM" />
        
        <!-- Basic Template -->
        <!-- Template for te Basic View -->
        <DataTemplate x:Key="BasicTemplate" DataType="{x:Type ViewModel:InputButtonsViewModel}" >
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="70" />
                    <RowDefinition Height="10"  />
                    <RowDefinition Height="200*" />
                </Grid.RowDefinitions>

                <!-- Add in the Display and Border. -->
                <View:DisplayView Grid.Row="0" HorizontalAlignment="Stretch" />
                <Border Grid.Row="0" BorderThickness="1" BorderBrush="Black" />

                <!-- Add in the Basic Button View. -->
                <View:InputButtonsView HorizontalAlignment="Stretch" Grid.Row="2"  />
            </Grid>
        </DataTemplate>

        <!-- Advanced Template -->
        <!-- Template for the Advanced View -->
        <DataTemplate x:Key="AdvanceTemplate" DataType="{x:Type ViewModel:InputButtonsViewModel}" >
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="70" />
                    <RowDefinition Height="10"  />
                    <RowDefinition Height="200*" />
                </Grid.RowDefinitions>

                <!-- Add in the Display and Border. -->
                <View:DisplayView Grid.Row="0" HorizontalAlignment="Stretch" />
                <Border Grid.Row="0" BorderThickness="1" BorderBrush="Black" />

                <!-- Add in the Advanced Button View. -->
                <View:AdvancedInputButtonsView Grid.Row="2" />
            </Grid>
        </DataTemplate>

        <!-- Graphing Templates/ -->
        <!-- Template for the Graphing Points View. -->
        <DataTemplate x:Key="PointsTemplate" >
            <GraphView:PointsView />
        </DataTemplate>

        <!-- Template for the Formula View. -->
        <DataTemplate x:Key="FormulaTemplate" >
            <GraphView:FormulaView />
        </DataTemplate>
    </Window.Resources>


    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="50*" />
            <RowDefinition Height="200*" />
        </Grid.RowDefinitions>

        <!-- Menu Bar -->
        <Menu Width="{Binding ElementName=grid_Main,Path=ActualWidth}" >
            <!-- File Menu -->
            <MenuItem Header="_File">
                <MenuItem Header="_Close" Command="{Binding Path=CloseCommand}" />
            </MenuItem>

            <!-- View Menu -->
            <MenuItem Header="_View">
                <MenuItem Header="Basic" IsChecked="{Binding Path=IsChecked, Converter={StaticResource EnumConverter}, ConverterParameter=Basic, Mode=TwoWay}" IsCheckable="True" Command="{Binding Path=CloseGraphViewCommand}" />
                <MenuItem Header="Advanced" IsChecked="{Binding Path=IsChecked, Converter={StaticResource EnumConverter}, ConverterParameter=Advance, Mode=TwoWay}" IsCheckable="True" Command="{Binding Path=CloseGraphViewCommand}" />
                <MenuItem Header="Graphing" >
                    <MenuItem Header="Points" IsChecked="{Binding Path=IsChecked, Converter={StaticResource EnumConverter}, ConverterParameter=Points, Mode=TwoWay}" IsCheckable="True" Command="{Binding Path=OpenGraphViewCommand}" />
                    <MenuItem Header="Formula" IsChecked="{Binding Path=IsChecked, Converter={StaticResource EnumConverter}, ConverterParameter=Formula, Mode=TwoWay}" IsCheckable="True" Command="{Binding Path=OpenGraphViewCommand}" />
            </MenuItem>
            </MenuItem>
            
            <!-- Graph Menu -->
            <MenuItem Header="_Graphing" >
                <MenuItem.Style>
                    <Style TargetType="{x:Type MenuItem}" >
                        <Setter Property="Visibility" Value="Hidden" />
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Path=IsChecked}" Value="Points">
                                <Setter Property="Visibility" Value="Visible" />
                            </DataTrigger>
                            
                            <DataTrigger Binding="{Binding Path=IsChecked}" Value="Formula">
                                <Setter Property="Visibility" Value="Visible" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </MenuItem.Style>
                <MenuItem DataContext="{StaticResource GraphVM}" Header="2D Graphing" IsChecked="{Binding Path=GraphTypeCheck, Converter={StaticResource EnumConverter}, ConverterParameter=Two_D, Mode=TwoWay}" IsCheckable="True" />
                <MenuItem DataContext="{StaticResource GraphVM}" Header="3D Graphing" IsChecked="{Binding Path=GraphTypeCheck, Converter={StaticResource EnumConverter}, ConverterParameter=Three_D, Mode=TwoWay}" IsCheckable="True" />
            </MenuItem>
        </Menu>

        <!-- Button View -->
        <ContentControl Grid.Row="1"  Content="{Binding}" >
            <ContentControl.Style>
                <Style TargetType="ContentControl">
                    <!-- Trigger to determine which View is displayed based on the Menu Radio Buttons. -->
                    <!-- Basically if IsChecked has the Value of "Basic" we set the ContentControl to Display the Basic Template. -->
                    <Style.Triggers>
                        <!-- Trigger for Basic View. -->
                        <DataTrigger Binding="{Binding Path=IsChecked}" Value="Basic" >
                            <Setter Property="ContentTemplate" Value="{StaticResource BasicTemplate}" />
                        </DataTrigger>

                        <!-- Trigger for Advanced View. -->
                        <DataTrigger Binding="{Binding Path=IsChecked}" Value="Advance" >
                            <Setter Property="ContentTemplate" Value="{StaticResource AdvanceTemplate}" />
                        </DataTrigger>


                        <!-- Trigger for Points View (From the Graphing Project). -->
                        <DataTrigger Binding="{Binding Path=IsChecked}" Value="Points" >
                            <Setter Property="ContentTemplate" Value="{StaticResource PointsTemplate}" />
                        </DataTrigger>

                        <!-- Trigger for Formula View (From the Graphing Project). -->
                        <DataTrigger Binding="{Binding Path=IsChecked}" Value="Formula" >
                            <Setter Property="ContentTemplate" Value="{StaticResource FormulaTemplate}" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </ContentControl.Style>
        </ContentControl>
    </Grid>
</Window>
